<?php

require_once 'Zend/Db/Table/Row/Abstract.php';

class Model_Table_Row extends Zend_Db_Table_Row_Abstract
{

    /**
     * @var string
     */
    protected $_kind = null;

    /**
     * @return string
     */
    public function getKind()
    {
        return $this -> _kind;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this -> id;
    }

    /**
     * @param array $params
     * @return string
     */
    public function getTitle()
    {
        return $this -> title;
    }

    /**
     * @param array $params
     * @return string
     */
    public function getUrl()
    {
        return '#';
    }

    /**
     * @param array $params
     * @return string
     */
    public function getImageUrl()
    {
        return '#';
    }

    /**
     * @param array $params
     * @return string
     */
    public function getAlias()
    {
        if (isset($this -> alias) && empty($this -> alias))
        {
            $this -> alias = preg_replace("#\s+#", '-', $this -> getTitle());
        }
        return $this -> alias;
    }

    public function getCreationDate()
    {
        return isset($this -> creation_date) ? $this -> creation_date : '';
    }

    public function getModificationDate()
    {
        return isset($this -> modification_date) ? $this -> modification_date : '';
    }

    public function updateAlias()
    {

        $table = Agis::getTable('core@alias');

        $uid = $this -> getId();

        $row = $table -> find($uid) -> current();

        if (!is_object($row))
        {
            $row = $table -> fetchNew();
            $row -> uid = $uid;
        }

        $row -> alias =  $this -> getAlias();
        $row -> save();
    }

}
